#ifndef MYFILE_H
#define MYFILE_H

//#define USE_STDIO

#define MRead 1
#define MReadWrite 2
#define MWriteCreate 3
#define MReadWriteCreate 4

#ifdef USE_STDIO
  #include <stdio.h>

  #define STDIN stdin
  #define STDOUT stdout
  #define STDERR stderr

  #define MYFile FILE*
  #define validFile(f) ((f)!=0)

  #define openFile(fname, mode) myopen(fname, mode)
  #define closeFile(file) fclose(file)

  #define printFile(file,format,...) fprintf(file, format, ##__VA_ARGS__)

  #define readFile(file, buf, len) myread(file, buf, len)
  #define writeFile(file, buf, len) mywrite(file, buf, len)

  #define seekFile(file, count, from) fseek(file, count, from)

  int myread(MYFile file, void *buf, int len);
  int mywrite(MYFile file, void *buf, int len);
  MYFile myopen(char *fname, int mode);
#else
  #define STDIN 0
  #define STDOUT 1
  #define STDERR 2

  #define MYFile int
  #define validFile(f) ((f)>=0)

  #define openFile(fname, mode) myopen(fname, mode)
  #define closeFile(file) close(file)

  #define printFile(file,format,...) myfprintf(file, format, ##__VA_ARGS__)

  #define readFile(file, buf, len) read(file, buf, len)
  #define writeFile(file, buf, len) write(file, buf, len)

  #define fileSeek(file, count, from) lseek(file, count, from)

  int myfprintf(MYFile file, char *format, ...);
  MYFile myopen(char *fname, int mode);
#endif


#endif
